Create feature symbology's from CSV template
The below code creates the new feature symbology's from the values reading from .csv file. This code creates feature symbology's under category point, line, profile, surface and solid.
This is an image of sample csv file used.
public void CreateFeatureSymbology()
{
//Get object space
Bentley.CifNET.CadSystem.IObjectSpaceManager objectSpaceManager = Bentley.CifNET.ServiceManager.Instance.GetService<Bentley.CifNET.CadSystem.IObjectSpaceManager>();
if (objectSpaceManager == null) return;
Bentley.CifNET.Objects.IObjectSpace objectSpace = objectSpaceManager.ObjectSpace;
if (objectSpace == null) return;
//Get or create civil model
Bentley.CifNET.Model.CivilModel civilModel = Bentley.CifNET.Model.CivilModel.GetCivilModelAndCreateIfDontExist(objectSpace);
if (civilModel == null) return;
//Get or create ContentManagementModel
Bentley.CifNET.ContentManagementModel.ContentManagementModel cmm = Bentley.CifNET.ContentManagementModel.ContentManagementModel.GetContentManagementModelAndCreateIfDontExist(objectSpace);
if (cmm == null) return;
//.CSV file name to read data for creating feature symbology's
string fileName = "D:\\DrawingProduction\\FeatureSymbologyTemplate.csv";
//Read all lines from csv file into array of strings
String[] lines = File.ReadAllLines(fileName);
Bentley.CifNET.ContentManagementModel.GeometryAspect featureSymbology = null;
for (int itr = 1; itr < lines.Length; itr++)
{
string[] fsParams = lines[itr].Split(',');
if (fsParams.Length != 2) continue;
//Read name and category for feature symbology from excel file
string featureSymbologyNameToSet = fsParams[0];
string type = fsParams[1];
//Create feature symbology for points category
if (type == "PointEntity2dInPlan")
{
featureSymbology = cmm.AddGeometryAspect(featureSymbologyNameToSet, typeof(Bentley.CifNET.GeometryModel.PointEntity2dInPlan), null);
}
//Create feature symbology for linear category
else if (type == "LinearEntity2dInPlan")
{
featureSymbology = cmm.AddGeometryAspect(featureSymbologyNameToSet, typeof(Bentley.CifNET.GeometryModel.LinearEntity2dInPlan), null);
}
//Create feature symbology for profile category
else if (type == "ProfileEntity")
{
featureSymbology = cmm.AddGeometryAspect(featureSymbologyNameToSet, typeof(Bentley.CifNET.GeometryModel.ProfileEntity), null);
}
//Create feature symbology for solid category
else if (type == "SolidEntity")
{
featureSymbology = cmm.AddGeometryAspect(featureSymbologyNameToSet, typeof(Bentley.CifNET.GeometryModel.SolidEntity), null);
}
//Create feature symbology for surface category
else if (type == "SurfaceEntity")
{
featureSymbology = cmm.AddGeometryAspect(featureSymbologyNameToSet, typeof(Bentley.CifNET.GeometryModel.SurfaceEntity), null);
}
if (featureSymbology == null) continue;
//save feature symbology
objectSpace.PersistChanges(cmm);
}
}
Output